#include<bits/stdc++.h>
using namespace std;
int main(){
    preopen("detect.in","r",stdin);
    preopen("detect.out","w",stdout);
    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        int d[n+5],v[n+5],a[n+5];
        for(int i=0;i<n;i++) cin>>d[i]>>v[i]>>a[i];
        int c=0;
        for(int i=0;i<n;i++){
            if(v[i]>V) c++;
        }
        cout<<c<<" "<<m-1;
    }
    return 0;
}